<html><head>
<title>client.py</title>
<meta name="Generator" content="htmlizer/[Twisted, version 17.9.0]" />
<link rel="alternate" href="client.py" type="text/x-python" />

</head>
<body>
<pre><span class="py-src-keyword">import</span> <span class="py-src-variable">socket</span>
<span class="py-src-variable">target_host</span> = <span class="py-src-string">"www.baidu.com"</span>
<span class="py-src-variable">target_port</span> = <span class="py-src-number">80</span>

<span class="py-src-variable">client</span> = <span class="py-src-variable">socket</span>.<span class="py-src-variable">socket</span>(<span class="py-src-variable">socket</span>.<span class="py-src-variable">AF_INET</span>, <span class="py-src-variable">socket</span>.<span class="py-src-variable">SOCK_STREAM</span>)
<span class="py-src-variable">client</span>.<span class="py-src-variable">connect</span>((<span class="py-src-variable">target_host</span>, <span class="py-src-variable">target_port</span>))
<span class="py-src-variable">client</span>.<span class="py-src-variable">send</span>(<span class="py-src-string">"GET / HTTP/1.1\r\nHost: baidu.com\r\n\r\n"</span>)
<span class="py-src-variable">response</span> = <span class="py-src-variable">client</span>.<span class="py-src-variable">recv</span>(<span class="py-src-number">4096</span>)
<span class="py-src-keyword">print</span> <span class="py-src-variable">response</span>
</pre>
</body>